package com.xiaoda.service.impl;

import com.xiaoda.dao.CommentDao;
import com.xiaoda.entity.Comment;
import com.xiaoda.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentDao commentDao;

    @Override
    public List<Comment> findAll() {
        return commentDao.findAll();
    }

    @Override
    public Comment findById(int id) {
        return commentDao.findById(id);
    }

    @Override
    public Comment findByIdFull(int id) {
        return commentDao.findByIdFull(id);
    }

    @Override
    public int commentArticleNum(int toAid) {
        return commentDao.commentArticleNum(toAid);
    }

    @Override
    public List<Comment> findAllByUid(String fromUid) {
        return commentDao.findAllByUid(fromUid);
    }

    @Override
    public int countCommentNum(String account) {
        return commentDao.countCommentNum(account);
    }

    @Override
    public int addComment(Comment comment) {
        return commentDao.addComment(comment);
    }

    @Override
    public List<Comment> findAllComments(int id) {
        return commentDao.findAllComments(id);
    }

    @Override
    public int deleteByUid(String uid) {
        return commentDao.deleteByUid(uid);
    }

    @Override
    public int deleteByAid(int aid) {
        return commentDao.deleteByAid(aid);
    }

    @Override
    public List<Comment> searchComment(Map<String, Object> map) {
        return commentDao.searchComment(map);
    }

    @Override
    public int updateComment(Map<String, Object> map) {
        return commentDao.updateComment(map);
    }

    @Transactional
    @Override
    public int deleteComment(int id) {
        commentDao.updateCommentById(id);
        return commentDao.deleteComment(id);
    }

    @Override
    public int updateCommentById(int id) {
        return commentDao.updateCommentById(id);
    }

}
